package com.tomvian.tools 
{
	/**
	 * EncryptedInt
	 * @author Thomas Vian
	 */
	public class EncryptedInt
	{
		//--------------------------------------------------------------------------
		//
		//  Properties
		//
		//--------------------------------------------------------------------------
		
		protected var _key:String;
		protected var _keyLength:uint;
		protected var _value:String;
		
		//--------------------------------------------------------------------------
		//
		//  Getters / Setters
		//
		//--------------------------------------------------------------------------
		
		public function get value():int 
		{ 
			var keyPos:int = 0;
			var valueArray:Array = [];
			for (var i:uint = 0, l:uint = _value.length; i < l; i++)
			{
				var keyShift:int = _key.charCodeAt(keyPos);
				valueArray.push(String.fromCharCode(_value.charCodeAt(i) - keyShift));
				keyPos++;
				if (keyPos >= _keyLength) keyPos = 0;
			}
			
			return int(valueArray.join("")); 
		}
		
		public function set value(value:int):void 
		{
			var valueStr:String = String(value);
			var valueArray:Array = [];
			var keyPos:int = 0;
			for (var i:uint = 0, l:uint = valueStr.length; i < l; i++)
			{
				var keyShift:int = _key.charCodeAt(keyPos);
				valueArray.push(String.fromCharCode(valueStr.charCodeAt(i) + keyShift));
				keyPos++;
				if (keyPos >= _keyLength) keyPos = 0;
			}
			
			_value = valueArray.join("");
		}
		
		//--------------------------------------------------------------------------
		//
		//  Constructor
		//
		//--------------------------------------------------------------------------
		
		public function EncryptedInt(key:String = "aKey") 
		{
			_key = key;
			_keyLength = key.length;
		}
		
		//--------------------------------------------------------------------------
		//
		//  Methods
		//
		//--------------------------------------------------------------------------
		
	}
}